// 获取元素节点
var totalnumber=document.getElementById('totalnumber')
var mengban=document.getElementById('mengban')
var idom=document.getElementById("bgcolor")
var idom1=document.getElementById('begin')

console.log(idom1);
var money=document.getElementsByClassName('money')[0]

console.log(money);
var time=document.getElementById('second')

console.log(time);
var number1=0

var second=15
time.innerHTML=`倒计时:${second}`
idom1.addEventListener('click',function(){
   mengban.style.display='none'
    idom1.style.display="none"
    addRedPacket()
    let compute=setInterval(function(){
    second--
    // console.log(second)
    time.innerHTML=`倒计时:${second}`

  setTimeout(addRedPacket,100);
  setTimeout(addRedPacket,100);
    if(second==0){
        clearInterval(compute)
        mengban.style.display=""
        totalnumber.style.display='block'
    }
},1000)



})

function addRedPacket(){

   
    var total=document.getElementById('total')
    var branch=document.getElementById('branch')
    var liDom = document.createElement('li');
    var Left = Math.random() * 70 +'%';
    liDom.innerHTML = '<img src="images/redpacket2.png">';
    liDom.style.left= `${Left}`; 

    document.getElementById('box').appendChild(liDom);


    
    liDom.getElementsByTagName('img')[0].addEventListener('click',function(e){

    var dis=e.currentTarget

    dis.style.display='none'

    var num=Math.ceil(Math.random()*10)
    number1+=num

    console.log(number1);
    total.innerText=number1
    branch.innerText= `+${num}`

    totalnumber.innerHTML=`总金额：${number1}`
    branch.style.display='inline-block'

    let timer=setTimeout(() => {
        branch.style.display='none'
    },300);
   
   
  
    })
   

}
